#include <iostream>
#include <stdexcept>
//#include <StdAfx.h>

using  namespace std;

//typedef double itemType; // need for another type, change it here

template <typename itemType>
class dynarray: public exception{
	private:
	// private variables
		itemType *ptr; // pointer to the first element of the array
		int cap; // capacity of the array
		int num; // size of the array
	// private function(s)
		void expand( ); // expand the array
	
	public:
	// private functions
		dynarray( int s = 0 ); // default size is 0
		dynarray( const dynarray &rhs );
		const dynarray &operator=( const dynarray & rhs);
		~dynarray();

		void push_back( itemType item );
		//The item is stored after the last element. If necessary the array is increased.

		itemType pop_back( ) throw (out_of_range);
		//Return the last element in the array. The element is removed from the array.
		//If the array is empty, a proper action should be taken

		void insert( itemType item, int pos );
		//Insert x at pos. All items in the range [pos,size]1 are moved one position upwards.
		//If necessary the array is increased. If pos are outside [0, size] a proper action2 should be taken.

		itemType erase( int pos );
		//Remove item at pos. All items in the range [pos, size} are moved one position downwards.
		//If pos is outside [0, size) a proper action should be taken.

		void clear( );
		//Remove all items.

		int size( ) const;
		//Return the size of the array.

		bool empty( ) const;
		//If the array is empty, return true.

		itemType &at( int pos ) const;
		//Return a non const reference to the content at pos. If pos is outside [0, size) a proper action should be taken
		
		//Overloaded operators
		itemType &operator[]( int pos ); // non const variant
		//Non-const: Return reference to the pos (the item at pos may by changed from the application).
		//const: Return a const reference to the pos (the item at pos cannot be changed)

		const itemType &operator[]( int pos ) const; // const variant

		dynarray operator+( const dynarray &rhs ); // Append two arrays

		dynarray &operator+=( const dynarray &rhs ); // Append two arrays. Result in the left side array.

		bool operator==( const dynarray &rhs ); // Compare two arrays. Return true if equal.

		bool operator!=( const dynarray &rhs ); // Compare two arrays. Return true if different

		friend ostream &operator<<( ostream &str, const dynarray &rhs ); //Output the content of the array

		// other functions
		itemType &back( );
		//Return a non const reference to the last element of the array. If the array is empty the reference is undefined

		itemType &front( );
		//Return a non const reference to the first element of the array. If the array is empty the reference is undefined

		int capacity( ) const; // Return the capacity of the array

		int contains( const itemType &item); // If x is present return the position, else return -1

		void resize( int newSize, itemType fill = itemType() );
		// If newSize is greater than the current size the array is expanded and filled with 'fill' or a proper default value.
		//If newSize is lesser than the current size the array is decreased to newSize and the surplus items are destroyed.

		bool operator< ( const dynarray &rhs );
		//Test if left side array is less than right side array. If the size of the left array are greater than the size
		//of the right array false is returned. The content of the arrays are compared from left to right.
		//If a left side element is less than the corresponding right side element, true is returned.
		//If size() of the left array are reached the comparisons are stopped and false is returned.

		bool operator<=( const dynarray &rhs );
		//Test if left side array is greater than or equal to right side array. The test is performed as !(lha < rhs)

		bool operator> ( const dynarray &rhs );
		//Test if left side array is greater than right side array. The test is opposite to operator <()

		bool operator>=( const dynarray &rhs );
		//Test if left side array is less than or equal to right side array. The test is performed as !(lha > rhs)	
};